<?php
$this->menu=array(
    array('label'=>'Generate this report','url'=>array('generate','id'=>$model->id), 'linkOptions'=>array('id'=>'generateReport')),
	array('label'=>'List report', 'url'=>array('list')),
	array('label'=>'Create report', 'url'=>array('create')),
	array('label'=>'Update report', 'url'=>array('update', 'id'=>$model->id)),
	array('label'=>'Delete report', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model->id),'confirm'=>'Are you sure you want to delete this item?')),
);
?>

<h1>View Report #<?php echo $model->id; ?></h1>

<?php $this->widget('zii.widgets.CDetailView', array(
	'data'=>$model,
	'attributes'=>array(
            'date:date:Report Date',
            'type:text:Report Type',
            'attn:text:Attn',
            'title',
            'remark',
	),
)); ?>

<hr />
<?php $this->beginClip('choose_cargo'); ?>
<div id="choose-cargo">
<div>
    <?php echo CHtml::link('back','#',array('id'=>'move','panel_id'=>'report_cargo'));?>
</div>
<div class="row">
    <?php echo CHtml::Label('searchText','search'); ?>
    <?php echo CHtml::TextField('search'); ?>
    <?php echo CHtml::Link('Search','#',array('id'=>'search','grid_id'=>'report-cargo-grid')); ?>
</div>
<div class="row">
<?php
	$this->widget('zii.widgets.grid.CGridView',array(
			'id'=>"report-cargo-grid",
			'dataProvider'=>$cargo->report_cargo(),
			'columns'=>array(
				array(
					'value'=>'$data->in_date',
					'header'=>'Date received',
					'type'=>'date',
				),
				array(
					'class'=>'CLinkColumn',
					'header'=>'Marking',
					'labelExpression'=>'$data->marking',
					'urlExpression'=>'CHtml::normalizeUrl(array("cargo/view","id"=>$data->id))'
				),
                                array(
					'value'=>'$data->shipper->cname',
					'header'=>'Shipper',
				),
				array(
					'value'=>'$data->consignee->cname',
					'header'=>'Consignee',
				),
				array(
					'header'=>'Dimension',
					'value'=>'$data->dimension->qty.$data->dimension->qty_type." / ".$data->dimension->wt.$data->dimension->wt_type." / ".$data->dimension->m3',
				),
				array(
					'class'=>'CLinkColumn',
					'label'=>'Add',
					'urlExpression'=>'CHtml::normalizeUrl(array("report/addcargo","cargo_id"=>$data->id,"id"=>'.$model->id.'))',
					'linkHtmlOptions'=>array('id'=>'add_cargo'),
				),
			),
		));
?>

</div>
</div>
<?php $this->endClip(); ?>

<?php $this->beginClip('report_cargo'); ?>
<div>
    <?php echo CHtml::link('Choose cargo','#',array('id'=>'move','panel_id'=>'choose_cargo'));?>
</div>
<div id="cargo-list">
<?php
$this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'choose-cargo-grid',
	'dataProvider'=>$model->listCargo(),
	'columns'=>array(
            array(
                    'value'=>'$data->in_date',
                    'header'=>'Date received',
                    'type'=>'date',
            ),
            array(
                    'class'=>'CLinkColumn',
                    'header'=>'Marking',
                    'labelExpression'=>'$data->marking',
                    'urlExpression'=>'CHtml::normalizeUrl(array("cargo/view","id"=>$data->id))'
            ),
            array(
                    'value'=>'$data->shipper->cname',
                    'header'=>'Shipper',
            ),
            array(
                    'value'=>'$data->consignee->cname',
                    'header'=>'Consignee',
            ),
            array(
                    'header'=>'Export date',
                    'value'=>'$data->export->export->etd',
                    'type'=>'date'
            ),
            array(
                'class'=>'CButtonColumn',
                'updateButtonUrl'=>'CHtml::normalizeUrl(array("cargo_export/update","id"=>$data->id))',
		'deleteButtonUrl'=>'CHtml::normalizeUrl(array("cargo_export/delete","id"=>$data->id))',
                'viewButtonUrl'=>'CHtml::normalizeUrl(array("cargo/view","id"=>$data->id))',
		'updateButtonOptions'=>array('id'=>'cargo-grid-update','dialog_width'=>'650'),
		'deleteButtonOptions'=>array('id'=>'remove_cargo'),
            )
	),
));

?>
</div>
<?php $this->endClip(); ?>
<?php $this->widget('application.widgets.wiNerdy.panel',array(
	'id'=>'report-panel',
	'panel'=>array(
		'report_cargo'=>$this->clips['report_cargo'],
		'choose_cargo'=>$this->clips['choose_cargo'],
	)
))?>

<?php
if(Yii::app()->request->enableCsrfValidation)
{
	$csrfTokenName = Yii::app()->request->csrfTokenName;
	$csrfToken = Yii::app()->request->csrfToken;
	$csrf = "\n\t\tdata:{ '$csrfTokenName':'$csrfToken' },";
}
else
	$csrf='';
$ExportReportUrl = CHtml::normalizeUrl(array('cargo_export/report/print/print'));
$script =<<<EOD
$('a#move').click(function(){
	$.winerdyPanel.MoveById('report-panel',$(this).attr('panel_id'));
	return false;
});
$('input#search').keypress(function(event){
	if(event.keyCode == '13'){
		$(this).next('a#search').click();
	}
});
$('a#search').click(function(){
	var searchInput = $(this).prev('input#search');
	$.fn.yiiGridView.update($(this).attr('grid_id'),{data:{searchText:$(searchInput).val()}});
	return false;
});
$('a#add_cargo').live('click',function(){
    var ajaxOptions = {
		url:$(this).attr('href'),
                $csrf
		success:function(data){
			$.fn.yiiGridView.update('report-cargo-grid');
			$.fn.yiiGridView.update('choose-cargo-grid');
			return;
		}
	};
	$.simplelogajax.ajax(ajaxOptions);
	return false;
});
$('#generateReport').click(function(){
    $.simplelogajax.popup($(this).attr('href'));
    return false;
})
EOD;
$cs = Yii::app()->getClientScript();
$cs->registerScript('report#View',$script);
?>
